<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function Parent() {
            this.parentProperty = 'I am from parent';
        }

        Parent.prototype.getParentValue = function () {
            return this.parentProperty;
        };

        function Child() {
            this.childProperty = 'I am from child';
        }

        // 关键步骤：将子构造函数的原型设置为父构造函数的实例
        Child.prototype = new Parent();

        Child.prototype.getChildValue = function () {
            return this.childProperty;
        };

        var childInstance = new Child();
        console.log(childInstance.getParentValue()); // 输出 'I am from parent'
        console.log(childInstance.getChildValue()); // 输出 'I am from child'
    </script>
</body>

</html>